import { request } from ".";
import type { RESPONSE } from "../types/base";
import type { LoginForm, RegisterForm, User } from "../types/user";

export const reqRegister = (form:RegisterForm)=>request.post<null,RESPONSE<User>>('/api/user/register',form)

export const reqLogin = (from:LoginForm)=>request.post<null,RESPONSE<User>&{token?:string}>('/api/user/login',from)

export const reqWhoAmI = () =>
    request.get<null, RESPONSE<User>>('/api/user/whoami')

export const reqCheckPwd = (username:string, password:string)=> 
    request.post<null, RESPONSE>('/api/user/checkpwd', {
    username,
    password
})

export const reqUpdatePwd = (username:string, password: string) =>
    request.post<null, RESPONSE>('/api/user/updatepwd', {username, password})

export const reqUpdateUser = (username:string,obj:object)=>
    request.put<null,RESPONSE<User>>(`/api/user/${username}`,obj)